import 'package:flutter/material.dart';
import '../../../utils/G.dart';

class ProductRecommendation extends StatefulWidget {
  List recommendation;
  ProductRecommendation({Key? key, required List this.recommendation})
      : super(key: key);

  @override
  _ProductRecommendationState createState() => _ProductRecommendationState();
}

class _ProductRecommendationState extends State<ProductRecommendation> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Wrap(
        children: widget.recommendation.isNotEmpty
            ? widget.recommendation.map((item) {
                return GestureDetector(
                    onTap: () {
                      Map<String, dynamic> p = {'id': item['id']};
                      G.router.navigateTo(
                          context, '/product_detail' + G.parseQuery(params: p));
                    },
                    child: Container(
                      width: G.width / 3,
                      child: Column(
                        children: [
                          G.imageWidget(item['image'], width: 100, height: 100),
                          Container(
                            alignment: Alignment.topLeft,
                            padding: const EdgeInsets.symmetric(horizontal: 10),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  item['store_name'].toString(),
                                  style: const TextStyle(fontSize: 14),
                                  overflow: TextOverflow.ellipsis,
                                ),
                                Text(
                                  "￥ " + item['price'].toString(),
                                  style: TextStyle(
                                      fontSize: 16,
                                      color: Theme.of(context).primaryColor),
                                  overflow: TextOverflow.ellipsis,
                                ),
                                Text(
                                  item['sales'].toString() + " 已售",
                                  style: const TextStyle(
                                    fontSize: 12,
                                  ),
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ],
                            ),
                          )
                        ],
                      ),
                    ));
              }).toList()
            : [const Center(child: Text('没有推荐'))],
      ),
    );
  }
}
